Usage analysis of common encryption modules of Python [MD5 sha crypt modules]


This article illustrates the common use of Python encryption modules. I will share it with you for your reference as follows:

1. md5 module

md5.new([arg]) Returns an md5 object, if given a parameter, it is equivalent to calling update(arg) md5.update(arg) Update the md5 object with the string parameter arg md5.digest() Returns a 16-byte digest generated by string passed to update without ascii characters md5.hexdigest() Returns the summary in hexadecimal format

import md5
a = md5.new('passwd')
a.digest()
  'v\xa2\x17;\xe692T\xe7/\xfaMm\xf1\x03\n'
a.hexdigest()
  '76a2173be6393254e72ffa4d6df1030a'
a.update('hello world')
a.digest()
  '\xb2\x83f\xb8\x14\xc9\xc6\x19k\x01\xfe\xd8\xd9\x8f\xe0H'
a.hexdigest()
  'b28366b814c9c6196b01fed8d98fe048'

2. sha module

The usage is the same as md51

import sha
b=sha.new('passwd')
b.digest()
 "0'LG\x90;\xd1\xba\xc7c;\xbf\tt1I\xeb\xab\x80_"
b.hexdigest()
 '30274c47903bd1bac7633bbf09743149ebab805f'
b.update('hello')
b.digest()
 'c\xc19\xb4]YGz\x85\xe8C\x8fF\xfe\x9e\xc3|\xb16\xba'
b.hexdigest()
 '63c139b45d59477a85e8438f46fe9ec37cb136ba

3.crypt

There is only one function in the crypt module, crypt(str,salt) — > string

from crypt import crypt
crypt('passwd','a')
 'aaIslqfNH03LA'
crypt('passwd','abc')
 'ab8RogIKnX0og'
crypt('passwd','a')
 'aaIslqfNH03LA'

PS: about encryption and decryption interested friends can also refer to the website online tools:

Text online encryption and decryption tools (including AES, DES, RC4, etc.) : http://tools.ofstack.com/password/txt\_encode

MD5 online encryption tool: http://tools.ofstack.com/password/CreateMD5Password

Online hash/hash algorithm encryption tool: http://tools.ofstack.com/password/hash\_encrypt

MD5/hash/ SHA-1 / SHA-2 / SHA-256 / SHA-512 / SHA-3 / RIPEMD-160 encryption tools: http://tools.ofstack.com/password/hash\_md5\_sha

Online sha1 sha224 / sha256 sha384 / sha512 encryption tools: http://tools.ofstack.com/password/sha\_encode

For more information about Python, please check out the topics of this website: summary of Python encryption and decryption algorithm and techniques, summary of Python coding and operation skills, Python data structure and algorithm tutorial, summary of Python function skills, summary of Python string operation skills, and classic tutorial of Python introduction and advanced skills.

I hope this article is helpful for you to design Python program.